package com.hsx.dao.user;

import com.hsx.dao.BaseDao;
import com.hsx.pojo.User;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class UserDaoImpl implements UserDao {
    //得到登录用户
    public User getLoginUser(Connection connection, String userCode) throws SQLException {

        PreparedStatement pstm=null;
        ResultSet rs=null;
        User user=null;
        if(connection!=null){
            String sql="select * from smbms_user where userCode=?";
            Object[] params={userCode};

            rs = BaseDao.execute(connection, sql, params, rs, pstm);
//            System.out.println("8");
            //下面这个以后写记得查查，挂了
            // java.sql.SQLException: Column 'createBy' not found.
            //因为createdBy没加d
            if(rs.next()){
                user= new User();
                user.setId(rs.getInt("id"));
                user.setUserCode(rs.getString("userCode"));
                user.setUserName(rs.getString("userName"));
                user.setUserPassword(rs.getString("userPassword"));
                user.setGender(rs.getInt("gender"));
                user.setBirthday(rs.getDate("birthday"));
                user.setPhone(rs.getString("phone"));
                user.setAddress(rs.getString("address"));
                user.setUserRole(rs.getInt("userRole"));
                user.setCreatedBy(rs.getInt("createdBy"));
                user.setCreationDate(rs.getTimestamp("creationDate"));
                user.setModifyBy(rs.getInt("modifyBy"));
                user.setModifyDate(rs.getTimestamp("modifyDate"));
            }
            BaseDao.closeResource(null,rs,pstm);

        }

//        System.out.println(user);
        return user ;
    }
}
